﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

namespace Shura.TestConsole
{
    class Program
    {       

        static void Main(string[] args)
        {
            Console.WriteLine("start");
            Console.WriteLine("-----------------------------");

            List<TestModel> testModels = new List<TestModel>();
            for(int i = 0;i<10;i++)
            {
                TestModel testModel = new TestModel();
                testModel.Id = i % 2;
                testModel.Guid = Guid.NewGuid();
                testModel.Sort = i;
                testModels.Add(testModel);
            }
            var tt = testModels.GroupBy(t=>new { Id = t.Id,Guid = t.Guid });
            
            Console.WriteLine(Util.Helpers.Json.ToJson(tt));
            //Algorithm.TestAlgorithm();
            //tttlllasync();
            //Util.WinkFault.WinkFault.Execute();
            Console.WriteLine("-----------------------------");
            Console.WriteLine("end");
            Console.ReadKey();
        }
        #region
        private static void t2()
        {
            var hexData = @" -欢_\迎加.%入斑#马~！";
            hexData = hexData.Replace("\\", "");
            hexData = Regex.Replace(hexData, "[ \\[ \\] \\^ \\-:*?\"<>《》|-]", "");
            Console.WriteLine(hexData);
        }
        private static void t4()
        {
            int[,] matrix = new int[,] { { 3,5,6,6,7}
                ,{4,7,8,5,3 }
            ,{ 5,9,0,4,2}
            ,{ 6,8,3,6,1} };

            int xmax = matrix.GetLength(0);
            int ymax = matrix.GetLength(1);
            var all = xmax + ymax - 1;
            for (int i = 0; i < all; i++)
            {
                string result = "";
                int x = 0;
                int y = 0;
                if (i < xmax)
                {
                    x = i;
                }
                else
                {
                    x = xmax-1;
                }
                for (int t = x; t >=0 ; t--)
                {
                    y = i - t;
                    if (y == ymax)
                    {
                        break;
                    }
                    result += matrix[t,y];
                }
                Console.WriteLine(result);
            }

            //Console.WriteLine(ymax);
        }
        #endregion


        #region  测试web

        public static async Task tttlllasync()
        {
            Console.WriteLine("000");
            await Task.Factory.StartNew(()=> {
                Thread.Sleep(5000);
            });
            Console.WriteLine("000");
        }
        public class ttl
        {
            public string State { get; set; }
            public string Msg { get; set; }
            public string Data { get; set; }
        }
        public static void TestHttpAsync()
        {
            try
            {
                TestModel testModel = new TestModel();
                Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
                keyValuePairs.Add("user", "wslzy");
                keyValuePairs.Add("pwd", "0");
                Action<string, System.Net.HttpStatusCode> action = (msg, status) =>
                {
                    if (status == System.Net.HttpStatusCode.Unauthorized)
                        Console.WriteLine("没有权限");
                };
                List<string> ttls = new List<string>();

                for (int i = 0; i < 10; i++)
                {
                    //var result = await _client.PostAsync("https://localhost:6001/api/loginapi/login", new FormUrlEncodedContent(param));
                    //http://localhost:6000/api/testapi/testnow
                    var result = Shura.Util.Helpers.Web.Client().Post("http://localhost:5000/api/testapi/login")
                    .OnFail(action)
                    .JsonData(testModel)
                    .IgnoreSsl()
                    .ResultAsync().Result;
                    ttls.Add(result);
                    Thread.Sleep(1000);
                    Console.WriteLine($"{i}:{result}");
                }

                foreach (var item in ttls)
                {
                    var result = Shura.Util.Helpers.Web.Client().Post("http://localhost:5000/api/testapi/time")
                    .OnFail(action)
                    .OnSuccess(action)
                    .Header("Authorization", "Bearer " + item)
                    .JsonData(testModel)
                    .IgnoreSsl()
                    .ResultAsync().Result;
                    Console.WriteLine($"{result}");
                }

                Console.WriteLine(ttls.Any(t => t != ttls.FirstOrDefault()));
            }
            catch (System.AggregateException ex)
            {
                Console.WriteLine("ai");
            }
        }
        #endregion

        #region 测试String
        public static void TestString()
        {
            Console.WriteLine("**********************************");
            string test = "我是老中医";
            string format = "{0}:{1}";
            string py = "wslzy";
            Util.Helpers.String @string = new Util.Helpers.String();
            @string.Append(test);
            Console.WriteLine(@string.ToString());
            @string.Append(format,test,py);
            Console.WriteLine(@string.ToString());
            @string.AppendLine(format, test, py);
            Console.WriteLine(@string.ToString());
            @string.Clear();
            Console.WriteLine(@string.ToString());
            @string.Append(test);
            @string.RemoveEnd("老中医");
            Console.WriteLine(@string.ToString());
            @string.Replace("老中医");
            Console.WriteLine(@string.ToString());
            Console.WriteLine(@string.Length);
            Console.WriteLine("**********************************");
            List<int> vs = new List<int>() {1,2,3,4,5,6,7,8,9 };
            Console.WriteLine(Util.Helpers.String.Join(vs,"\""));
            string firstStr = @"Hello World!
I'm God!";
            Console.WriteLine(Util.Helpers.String.FirstLowerCase(firstStr));
            Console.WriteLine(Util.Helpers.String.PinYin("蚩尤"));
            Console.WriteLine(Util.Helpers.String.PinYin(firstStr));
        }
        #endregion

        #region 测试Regex
        public static void TestRegex()
        {
            Console.WriteLine("**********************************");
            var match1 = @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$";
            var match2 = @"(Teleware.Sea)";
            var match3 = @"\{([0-9]+)\}";
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Regex.GetValues("asdfkkj{a123}{0}{123}{124b}", match3, new string[] { "$1" })));
            Console.WriteLine(Util.Helpers.Regex.GetValue("Teleware.Sea.lll", match2,"asdb$1$1$2"));
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Regex.Split("Teleware.Sea.Abc", match2)));
            Console.WriteLine(Util.Helpers.Regex.Replace("Teleware.Sea.lll", match2, "Teleware.Lands"));
            Console.WriteLine(Util.Helpers.Regex.IsMatch("lll@qq.com",match1));
        }
        #endregion

        #region 测试Reflection
        public static void TestReflection()
        {
            TestModel testModel = new TestModel()
            {
                Guid = Guid.NewGuid(),
                Id = 1,
                Name = "我是老中医",
                Sort = null,
                CreateTime = DateTime.Now,
                IsDelete = true,
                MyEnum = MyEnum.ddd
            };
            Console.WriteLine("**********************************");
            Console.WriteLine(Shura.Util.Helpers.Reflection.GetDescription<TestVM>());
            Console.WriteLine(Shura.Util.Helpers.Reflection.GetDescription<TestVM>("Guid"));
            Console.WriteLine(Shura.Util.Helpers.Reflection.GetDescription(typeof(TestVM),"Guid"));
            Type type = typeof(TestVM);
            var member = type.GetMember("Name");
            //Console.WriteLine(Util.Helpers.Json.ToJson(Shura.Util.Helpers.Random.Sort(vs)));
            Console.WriteLine("**********************************");
            Console.WriteLine(Shura.Util.Helpers.Reflection.GetDisplayName<TestVM>());
            Console.WriteLine(Shura.Util.Helpers.Reflection.GetDisplayName(member[0]));
            Console.WriteLine(Shura.Util.Helpers.Reflection.GetDisplayNameOrDescription<TestVM>());
            Console.WriteLine("**********************************");
            System.Reflection.Assembly assembly = Util.Helpers.Reflection.GetAssembly("Shura.Util");
            Console.WriteLine(Util.Helpers.Json.ToJson(Shura.Util.Helpers.Reflection.GetInstancesByInterface<Util.Contexts.IContext>(assembly)));
            var member2 = type.GetMember(".ctor");
            Console.WriteLine(Util.Helpers.Reflection.IsInt(member2[0]));
            Console.WriteLine("**********************************");
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Reflection.GetPublicProperties(testModel)));
            var path = Environment.CurrentDirectory ;//"E:\\张嵩\\myself\\Shura\\Shura.Util";
            //Console.WriteLine(Util.Helpers.Json.ToJsonConvert(Util.Helpers.Reflection.GetAssemblies(path)));
        }
        #endregion

        #region 测试Random
        public static void TestRandom()
        {
            Console.WriteLine("**********************************");
            Shura.Util.Helpers.Random random = new Util.Helpers.Random();
            Console.WriteLine(random.Next(100));
            Console.WriteLine(random.Next(1,100));
            List<int> vs = new List<int>();
            vs.Add(1);
            vs.Add(2);
            vs.Add(3);
            vs.Add(4);
            Console.WriteLine(Util.Helpers.Json.ToJson( Shura.Util.Helpers.Random.Sort(vs)));
        }
        #endregion

        #region 测试lamdba
        private static void TestLamdba()
        {
            TestModel testModel = new TestModel()
            {
                Guid = Guid.NewGuid(),
                Id = 1,
                Name = "我是老中医",
                Sort = null,
                CreateTime = DateTime.Now,
                IsDelete = true,
                MyEnum = MyEnum.ddd
            };

            Expression<Func<TestModel, object>> expression = t=>t.IsDelete;
            var aaa = Util.Helpers.Lambda.GetMember(expression);

            var bbb = Expression.Constant(testModel);
            Console.WriteLine(bbb.Value);

            Expression<Func<TestModel, object[]>> expression2 = t => new object[] { t.Guid, t.Id };

            MemberExpression memberExpression = Expression.Property(bbb, "Sort");

            Expression<Func<TestModel, object>> expression3 = t => t.Sort == 666;

            Expression<Func<TestModel, object>> expression4 = t => t.Sort;

            Expression<Func<TestModel, bool>> expression5 = t => !(t.Sort == 666 || t.Name == "AndAlso") && t.IsDelete;

            Expression<Func<TestModel,bool>> expression6 = t=>t.IsDelete;

            Expression<Func<bool>> expression7 = () => new TestModel().IsDelete;

            Expression<Func<TestModel, MyEnum>> expression8 = t => t.MyEnum;

            MemberExpression memberExpression2 = Expression.PropertyOrField(bbb, "IsDelete");

            Console.WriteLine("**********************************");
            Console.WriteLine(aaa.Name);
            Console.WriteLine(Util.Helpers.Lambda.GetName(expression));
            Console.WriteLine(Util.Helpers.Lambda.GetMemberName(memberExpression));
            var names = Util.Helpers.Lambda.GetNames(expression2);
            Console.WriteLine(Util.Helpers.Json.ToJson(names));
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Lambda.GetValue(expression3)));
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Lambda.GetParameter(expression4)));
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Lambda.GetConditionCount(expression5)));
            Console.WriteLine("**********************************");
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Lambda.GetAttribute<TestModel,bool, DataFieldAttribute>(expression6)));
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Lambda.GetAttribute<DataFieldAttribute>(expression6)));
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Lambda.GetAttribute<bool, DataFieldAttribute>(expression7)));
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Lambda.GetAttributes<TestModel, MyEnum, DataFieldAttribute>(expression8)));
            Console.WriteLine("**********************************");
            var lll = Util.Helpers.Lambda.Constant(memberExpression2, true);
            Console.WriteLine(Util.Helpers.Json.ToJson(lll));
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Lambda.Equal<TestModel>("IsDelete",true).Compile()(testModel)));
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Lambda.NotEqual<TestModel>("IsDelete", true).Compile()(testModel)));
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Lambda.Greater<TestModel>("CreateTime", DateTime.Now).Compile()(testModel)));
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Lambda.GreaterEqual<TestModel>("CreateTime", DateTime.Now).Compile()(testModel)));
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Lambda.Less<TestModel>("CreateTime", DateTime.Now).Compile()(testModel)));
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Lambda.LessEqual<TestModel>("CreateTime", DateTime.Now).Compile()(testModel)));
            Console.WriteLine("**********************************");
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Lambda.Starts<TestModel>("Name", "我").Compile()(testModel)));
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Lambda.Ends<TestModel>("Name", "我").Compile()(testModel)));
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Lambda.Contains<TestModel>("Name", "我").Compile()(testModel)));
            Console.WriteLine(Util.Helpers.Json.ToJson(Util.Helpers.Lambda.ParsePredicate<TestModel>("Name", "我",Util.Datas.Queries.Operator.Contains).Compile()(testModel)));
        }
        #endregion

        #region 测试ExpressionParser
        public static void TestExpressionParser()
        {
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>()
            {
                ["a"] = "z",
                ["w"] = "x",
                ["e"] = "c",
            };

            var param = new
            {
                t = keyValuePairs
            };
            var result = Util.ExpressionParser.ExpressionParse_Yacep<bool>.Execute("t.ContainsKey(\"a\") && !t.ContainsKey(\"q\")", param);
            Console.WriteLine(result);

            var param2 = new
            {
                c = keyValuePairs
            };
            result = Util.ExpressionParser.ExpressionParse_Yacep<bool>.Execute("c.ContainsKey(\"||\")", param2);
            Console.WriteLine(result);
        }

        public static void TestEpCompareSTL()
        {
            Stopwatch stopwatch1 = new Stopwatch();
            Stopwatch stopwatch2 = new Stopwatch();
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>()
            {
                ["a"] = "z",
                ["w"] = "x",
                ["e"] = "c",
            };
            var param = new
            {
                t = keyValuePairs
            };
            var result = false;
            stopwatch1.Start();
            for(int i=0;i<10;i++)
            {
                result = Util.StringToLambda.LambdaParser.Compile<Func<Dictionary<string, string>, bool>>("t=>t.ContainsKey(\"a\") && !t.ContainsKey(\"q\")")(keyValuePairs);
            }
            stopwatch1.Stop();
            Console.WriteLine("stl:" + result);
            Console.WriteLine("stl:" + stopwatch1.ElapsedMilliseconds);

            stopwatch2.Start();
            for (int i = 0; i < 10; i++)
            {
                result = Util.ExpressionParser.ExpressionParse_Yacep<bool>.Execute("t.ContainsKey(\"a\") && !t.ContainsKey(\"q\")", param);
            }
            stopwatch2.Stop();
            Console.WriteLine("ep:" + result);
            Console.WriteLine("ep:" + stopwatch2.ElapsedMilliseconds);
        }
        #endregion

        #region 测试StringToLambda
        public static void TestStringToLambda()
        {
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>()
            {
                ["a"] = "z",
                ["w"] = "x",
                ["e"] = "c",
            };

            Expression<Func<Dictionary<string, string>,string, bool>> expr = Util.StringToLambda.LambdaParser.Parse<Func<Dictionary<string, string>, string, bool>>("t=>t.ContainsKey(\"a\") && !t.ContainsKey(\"q\")");
            var result = expr.Compile()(keyValuePairs,"132");
            Console.WriteLine(result);

            result = Util.StringToLambda.LambdaParser.Compile<Func<Dictionary<string, string>, bool>>("c=>c.ContainsKey(\"||\")")(keyValuePairs);
            Console.WriteLine(result);
        }
        #endregion

        #region 测试json
        public static void TestJson()
        {
            TestModel testModel = new TestModel()
            {
                Guid = Guid.NewGuid(),
                Id = 1,
                Name = "我是老中医",
                Sort = null,
                CreateTime = DateTime.Now,
                IsDelete = true
            };
            var json = Util.Helpers.Json.ToJson(testModel);
            var newModel = Util.Helpers.Json.ToObject<TestModel>(json);
            Console.WriteLine(json);
        }
        #endregion

        #region 测试id
        public static void TestId()
        {
            Console.WriteLine(Util.Helpers.Id.GetGuid());
            Console.WriteLine(Util.Helpers.Id.GetGuid());
            Console.WriteLine(Util.Helpers.Id.ObjectId());
            Console.WriteLine(Util.Helpers.Id.ObjectId());
            Console.WriteLine(Util.Helpers.Id.Guid());
            Console.WriteLine(Util.Helpers.Id.Guid());
            Util.Helpers.Id.SetId("lll");
            Console.WriteLine(Util.Helpers.Id.ObjectId());
            Util.Helpers.Id.Reset();
            Console.WriteLine(Util.Helpers.Id.ObjectId());
        }
        #endregion

        #region 测试enum

        public static void TestEnum()
        {
            //System.StringSplitOptions.RemoveEmptyEntries
            Console.WriteLine(Util.Helpers.Enum.Parse<StringSplitOptions>("RemoveEmptyEntries"));
            Console.WriteLine(Util.Helpers.Enum.Parse<StringSplitOptions>("1"));
            Console.WriteLine(Util.Helpers.Enum.Parse<StringSplitOptions>(1));
            Console.WriteLine("***************************");
            Console.WriteLine(Util.Helpers.Enum.GetName<StringSplitOptions>("RemoveEmptyEntries"));
            Console.WriteLine(Util.Helpers.Enum.GetName<StringSplitOptions>(1));
            Console.WriteLine(Util.Helpers.Enum.GetName<StringSplitOptions>("1"));
            Console.WriteLine(Util.Helpers.Enum.GetName<StringSplitOptions>(StringSplitOptions.None));
            Console.WriteLine("***************************");
            Console.WriteLine(Util.Helpers.Enum.GetValue<StringSplitOptions>("none"));
            Console.WriteLine(Util.Helpers.Enum.GetValue<StringSplitOptions>(1));
            Console.WriteLine(Util.Helpers.Enum.GetValue<StringSplitOptions>("3"));
            Console.WriteLine(Util.Helpers.Enum.GetValue<StringSplitOptions>(StringSplitOptions.None));
            Console.WriteLine("***************************");
            Console.WriteLine(Util.Helpers.Enum.GetDescription<MyEnum>("aaa"));
            Console.WriteLine(Util.Helpers.Enum.GetDescription<MyEnum>(0));
            Console.WriteLine(Util.Helpers.Enum.GetDescription<MyEnum>(1));
            Console.WriteLine("***************************");
            var result = Util.Helpers.Enum.GetItems<MyEnum>();
            Util.Helpers.String @string = new Util.Helpers.String();
            foreach (var item in result)
            {
                @string.Append(item.Text);
                @string.Append(item.Value);
                @string.AppendLine();
            }
            Console.WriteLine(@string);
        }
        #endregion

        #region 测试convert
        public static void TestConvert()
        {
            Console.WriteLine(Util.Helpers.Convert.ToInt("123.5"));
            Console.WriteLine(Util.Helpers.Convert.ToIntOrNull(""));
            Console.WriteLine(Util.Helpers.Convert.ToLong(""));
            Console.WriteLine(Util.Helpers.Convert.ToLongOrNull(""));
            Console.WriteLine("***************************");
            Console.WriteLine(Util.Helpers.Convert.ToFloat("123.555"));
            Console.WriteLine(Util.Helpers.Convert.ToFloatOrNull("123.555", 2));
            Console.WriteLine(Util.Helpers.Convert.ToDouble("", 3));
            Console.WriteLine(Util.Helpers.Convert.ToDoubleOrNull("", null));
            Console.WriteLine(Util.Helpers.Convert.ToDecimal("asdf", 2));
            Console.WriteLine(Util.Helpers.Convert.ToDecimalOrNull("123123.5661141651", 15));
            Console.WriteLine("***************************");
            Console.WriteLine(Util.Helpers.Convert.ToBool(""));
            Console.WriteLine(Util.Helpers.Convert.ToBoolOrNull(""));
            Console.WriteLine(Util.Helpers.Convert.ToBool(null));
            Console.WriteLine(Util.Helpers.Convert.ToBoolOrNull(null));
            Console.WriteLine(Util.Helpers.Convert.ToBool("yes"));
            Console.WriteLine(Util.Helpers.Convert.ToBool("YES"));
            Console.WriteLine(Util.Helpers.Convert.ToBool("success"));
            Console.WriteLine(Util.Helpers.Convert.ToBool("SUCCESS"));
            Console.WriteLine(Util.Helpers.Convert.ToBool("no"));
            Console.WriteLine(Util.Helpers.Convert.ToBool("NO"));
            Console.WriteLine(Util.Helpers.Convert.ToBool("是"));
            Console.WriteLine(Util.Helpers.Convert.ToBool("否"));
            Console.WriteLine(Util.Helpers.Convert.ToBool("确定"));
            Console.WriteLine(Util.Helpers.Convert.ToBool("取消"));
            Console.WriteLine("***************************");
            Console.WriteLine(Util.Helpers.Convert.To<DateTime>("2018-1-1"));
            Util.Helpers.String strBytes = new Util.Helpers.String();
            var bytes = Util.Helpers.Convert.ToBytes("我");
            foreach (var item in bytes)
            {
                strBytes.Append(item);
                strBytes.Append(" ");
            }
            Console.WriteLine(strBytes.ToString());
        }
        #endregion

        #region 测试common
        public static void TestCommon()
        {
            Console.WriteLine("Shura.Util.Helpers.Common.Line" + Shura.Util.Helpers.Common.Line);
            Console.WriteLine("Shura.Util.Helpers.Common.Line" + Shura.Util.Helpers.Common.GetPhysicalPath("123"));
            Console.WriteLine("Shura.Util.Helpers.Common.Line" + Shura.Util.Helpers.Common.GetWebRootPath("456"));
            Console.WriteLine("Shura.Util.Helpers.Common.Line" + Shura.Util.Helpers.Common.GetType<DateTime>().ToString());
        }
        #endregion

        #region 20190121 测试加密解密 encrypt
        public void TestEncrypt()
        {
            var str = string.Empty;
            str = Util.Helpers.Encrypt.AesEncrypt("wslzy");
            Console.WriteLine("AesEncrypt:" + str);
            str = Util.Helpers.Encrypt.AesDecrypt(str);
            Console.WriteLine("AesDecrypt:" + str);

            str = Util.Helpers.Encrypt.DesEncrypt("wslzy");
            Console.WriteLine("DesEncrypt:" + str);
            str = Util.Helpers.Encrypt.DesDecrypt(str);
            Console.WriteLine("DesEncrypt:" + str);

            str = Util.Helpers.Encrypt.Md5By16("wslzy");
            Console.WriteLine("Md5By16:" + str);
            str = Util.Helpers.Encrypt.Md5By32("wslzy");
            Console.WriteLine("Md5By32:" + str);

            //秘钥格式 PKCS#1
            var publicKey = @"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCkUTO3HqkLw5HtOtl5u7cwYzCM
4bTRnYShiimOjdbA6YL55ejWC3QV4rrwSNveZw3SAzquPpeMhzXZdmwLa8gwWuLc
QDft3OlmRauw6J0HuPAFE+wezqTP7NkcfJw0+OHfYhJHp07CAFIF/Y6H0AYi2kVb
gdMZaBzlCCp5B6vntwIDAQAB";
            var privateKey = @"MIICXQIBAAKBgQCkUTO3HqkLw5HtOtl5u7cwYzCM4bTRnYShiimOjdbA6YL55ejW
C3QV4rrwSNveZw3SAzquPpeMhzXZdmwLa8gwWuLcQDft3OlmRauw6J0HuPAFE+we
zqTP7NkcfJw0+OHfYhJHp07CAFIF/Y6H0AYi2kVbgdMZaBzlCCp5B6vntwIDAQAB
AoGALcTV3C0/dktkm5Oc0qT62GYzNnVYDFsNKoHKztkAodNpQXpMv0eJb4nWpZS7
Htki/Fsck+mor41UmTIR06HorJJg30cVtKqiaouxlrc+TQF4M7nmzYQvVwoaDDxZ
+azP6jMvqJmdert0HN3jPcYGknJxKmc6QTUpisMa333RLaECQQDFKf8I014OPtId
XtyDy5hIUlgm93xCL64ZksYqXlApDp29+hvUlHyXphG2mKCEPVFPj1soWbO7oDZg
AMiU2v4LAkEA1VntgNhYh65qABPz45RAJ6NEq8/wKUmwGZpakc3X2iSlUO9pYRF0
+7ap9dhm83eMb92OK+WeE40xquhDtSFEhQJBAIOHaKOyneRS9Eizp9gkUgqtJDGa
mEJvHG3jBF/vWvqIzaKW30oJZLSmDNsLJsoRPdUdhWp9rPFWB/AzlZv4G9ECQHUB
urVc8UCIMO4WAz2egoi6i+DGS2n5VbDU7DLmdyjVzCxVALARiNy7Uv7XTa7cs5Ju
KZh9d3I1jzWx5+AgfJkCQQC03Cq1BqKk455Z9hXs4EIxZLIhvGP8R6Gj5v6wXeYu
jziCMjZnfq4mJVcCC5tVqRdKq3EFgQAyCdY6KcT4QZVw";

            str = Util.Helpers.Encrypt.Rsa2Sign("wslzy", privateKey);
            Console.WriteLine("Rsa2Sign:" + str);
            bool result = Util.Helpers.Encrypt.Rsa2Verify("wslzy", publicKey, str);
            Console.WriteLine("Rsa2Verify:" + result);
        }
        #endregion
    }

    #region 枚举实例
    public enum MyEnum
    {
        [System.ComponentModel.Description("我是老中医")]
        aaa,
        bbb,
        ccc,
        ddd=999
    }
    #endregion

    #region 实体测试
    [System.ComponentModel.Description("我是老中医Description")]
    [System.ComponentModel.DisplayName("我是老中医DisplayName")]
    public class TestVM
    {
        public TestVM()
        {
            keyValuePairs = new Dictionary<string, string>();
        }
        public Dictionary<string, string> keyValuePairs { get; }
        public string field;
        public Guid Guid { get; set; }
        public int Id { get; set; }
        [System.ComponentModel.DisplayName("我是老中医DisplayName")]
        [System.ComponentModel.DataAnnotations.Display(Name= "我是老中医Display")]
        public string Name { get; set; }
        [DataField("lll")]
        public int? Sort { get; set; }
        public DateTime? CreateTime { get; set; }
        [DataFieldAttribute1("ttt")]
        public bool IsDelete { get; set; }
        [DataFieldAttribute1("ttt")]
        [DataFieldAttribute2("wslzy")]
        public MyEnum MyEnum { get; set; }
        
    }
    public class TestModel
    {
        public TestModel()
        { }
        public TestModel(string name)
        {
            Name = name;
        }
        public string field;
        public Guid Guid { get; set; }
        public int Id { get; set; }
        public string Name { get; set; }
        [DataField("lll")]
        public int? Sort { get; set; }
        public DateTime? CreateTime { get; set; }
        [DataFieldAttribute1("ttt")]
        public bool IsDelete { get; set; }
        [DataFieldAttribute1("ttt")]
        [DataFieldAttribute2("wslzy")]
        public MyEnum MyEnum { get; set; }

        public string user { get; set; } = "wslzy";
        public string pwd { get; set; } = "0";
    }
    public class CTestModel:TestModel
    {
        public CTestModel(string name):base(name)
        {
            CName = name;
        }
        public string CName { get; set; }
        public bool TTMethod()
        {
            Console.WriteLine("ttmethod");
            return true;
        }
    }

    [AttributeUsage(AttributeTargets.Property)]
    public class DataFieldAttribute : Attribute
    {
        /// <summary>
        /// 表对应的字段名
        /// </summary>
        public string ColumnName { set; get; }

        public DataFieldAttribute(string columnName)
        {
            ColumnName = columnName;
        }
    }
    public class DataFieldAttribute1 : DataFieldAttribute
    {
        public DataFieldAttribute1(string columnName) : base(columnName)
        {
        }
    }
    public class DataFieldAttribute2 : DataFieldAttribute
    {
        public DataFieldAttribute2(string columnName) : base(columnName)
        {
        }
    }
    #endregion
}
